using System.Collections.Generic;
using UnityEngine;

public class TTCameraController : MonoBehaviour
{
	public delegate void OnHitPointUpdatePos(Vector3 hitPosition, float cameraOffsetSignX, float cameraOffsetSignZ);

	public delegate void OnWaitTransformSet(Transform ballTransform);

	public delegate void OnWaitDone();

	public delegate void OnBehaviourDoneNotify();

	public OnHitPointUpdatePos onHitPointUpdatePos;

	public OnWaitTransformSet onWaitTransformSet;

	public OnWaitDone onWaitDone;

	public OnBehaviourDoneNotify onBehaviourDoneNotify;

	private CameraBehavioursDB.CameraGroupType activeGroup = CameraBehavioursDB.CameraGroupType.Group1;

	private TTCameraBehaviour.GameplayIntervalType activePositionType = TTCameraBehaviour.GameplayIntervalType.RegularPlayCamera;

	private TTCameraOptions cameraOptions;

	public TTCameraBehaviour cameraBehaviour { get; protected set; }

	public Camera camera
	{
		get
		{
			return GetComponent<Camera>();
		}
	}

	private void InitCameraView()
	{
		int usedCameraView = GGPlayerSettings.instance.Model.usedCameraView;
		List<CameraBehavioursDB.CameraGroupType> list = CameraBehavioursDB.instance.UsedCameraGroupTypes();
		usedCameraView %= list.Count;
		CameraBehavioursDB.CameraGroupType newGroup = list[usedCameraView];
		ChangeCameraGroup(newGroup);
	}

	private void Awake()
	{
		InitBehaviour();
		InitCameraView();
	}

	public void Refresh()
	{
		InitBehaviour();
	}

	private void InitBehaviour()
	{
		onHitPointUpdatePos = null;
		onWaitTransformSet = null;
		onWaitDone = null;
		TTCameraBehaviour tTCameraBehaviour = cameraBehaviour;
		cameraBehaviour = CameraBehavioursDB.instance.GetCameraBehaviour(activeGroup, activePositionType);
		if (tTCameraBehaviour != cameraBehaviour && tTCameraBehaviour != null)
		{
			tTCameraBehaviour.OnEnd();
		}
		if (cameraBehaviour != null)
		{
			cameraBehaviour.Start(camera, this, cameraOptions);
		}
	}

	public void ChangeGameplayInterval(TTCameraBehaviour.GameplayIntervalType newInterval, TTCameraOptions cameraOptions)
	{
		activePositionType = newInterval;
		this.cameraOptions = cameraOptions;
		InitBehaviour();
	}

	public void ChangeCameraGroup(CameraBehavioursDB.CameraGroupType newGroup)
	{
		activeGroup = newGroup;
		InitBehaviour();
	}

	public void HitPointUpdate(Vector3 hitPosition, float cameraOffsetSignX, float cameraOffsetSignZ)
	{
		if (onHitPointUpdatePos != null)
		{
			onHitPointUpdatePos(hitPosition, cameraOffsetSignX, cameraOffsetSignZ);
		}
	}

	public void ServeBallPosition(Transform ballTransform)
	{
		if (onWaitTransformSet != null)
		{
			onWaitTransformSet(ballTransform);
		}
	}

	private void LateUpdate()
	{
		if (cameraBehaviour != null)
		{
			cameraBehaviour.Update();
		}
	}

	public void BehaviourDone()
	{
		if (onBehaviourDoneNotify != null)
		{
			onBehaviourDoneNotify();
		}
	}

	public void OnActionWaitDone()
	{
		if (onWaitDone != null)
		{
			onWaitDone();
		}
	}
}
